﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product;
using ERP_RORZE_DLL.Product.Base;

namespace ERP_RORZE.Product.BusOder
{
    public partial class Frm_BusOderAdd : DevExpress.XtraEditors.XtraForm
    {
        ClsBusOderTable busoder = new ClsBusOderTable();
        ClsBusOderDAO clsBusOderDAO = new ClsBusOderDAO();
        public event EventHandler Re_Load;
        DataTable dt;
        public Frm_BusOderAdd()
        {
            InitializeComponent();
        }

        private void Frm_BusOderAdd_Load(object sender, EventArgs e)
        {
            // lấy danh sách PartID truyền vào cbPartID
            dt = clsBusOderDAO.GetPartID();
            cbPartID.DataSource = dt;
            cbPartID.DisplayMember = "PartNo";
            cbPartID.ValueMember = "PartNo";

            //Lấy danh sách MONo truyền vào cbMONo
            dt = clsBusOderDAO.GetMONo();
            cbMONo.DataSource = dt;
            cbMONo.DisplayMember = "MONo";
            cbMONo.ValueMember = "MONo";
        }
        void ThongBao(string name)
        {
            MessageBox.Show("Chưa nhập " + name + ". Vui lòng nhập lại");
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtBusOderNo.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.BOderNo);
            }
            else if (txtBlastQty.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.BlastQty);
            }
            else if (txtChange.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.Change);
            }
            else if (txtHelisertQty.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.HelisertQty);
            }
            else if (txtImpordFrom.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.Imported);
            }
            else if (txtMOQty.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.MOQty);
            }
            else if (txtNote.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.Note);
            }
            else if (txtPlanNo.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.planNo);
            }
            else if (txtQty.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.Qty);
            }
            else if (txtRawQty.Text == "")
            {
                ThongBao(clsConstantsdb.Entities.ClsDBBusOder.FieldName.RawQty);
            }
            else
            {
                busoder.BOderNo = txtBusOderNo.Text;
                busoder.Date = dateDate.Value;
                busoder.Dealine = dateDeadLine.Value;
                busoder.ChangeDate = dateChangeDate.Value;
                busoder.BlastQty = int.Parse(txtBlastQty.Text);
                busoder.Change = txtChange.Text;
                busoder.Finished = checkFinished.Checked;
                busoder.HelisertQty = int.Parse(txtHelisertQty.Text);
                busoder.Imported = checkImported.Checked;
                busoder.ImportFrom = txtImpordFrom.Text;
                busoder.MONo = cbMONo.Text;
                busoder.MOQty = int.Parse(txtMOQty.Text);
                busoder.Note = txtNote.Text;
                busoder.PartID = cbPartID.Text;
                busoder.PlanNo = txtPlanNo.Text;
                busoder.Qty = int.Parse(txtQty.Text);
                busoder.RawQty = int.Parse(txtRawQty.Text);
                busoder.Started = checkStarted.Checked;
                clsBusOderDAO.Insert(busoder);
                this.Re_Load(sender, e);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}